package cn.gong.movie.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import framework.utils.LogUtils;

public class DateUtils1 {
	private static ArrayList<String> DAY_31 = new ArrayList<String>();
	private static ArrayList<String> DAY_30 = new ArrayList<String>();
	private static ArrayList<String> DAY_29 = new ArrayList<String>();
	private static ArrayList<String> DAY_28 = new ArrayList<String>();
	private static ArrayList<String> MONTH = new ArrayList<String>();
	private static ArrayList<String> YEAR_TOTAL = new ArrayList<String>();

	static {
		for (int i = 0; i < 31; i++) {
			String day = (i + 1) + "";

			if (day.length() == 1) {
				day = "0" + day;
			}

			switch (i) {
			default:
				DAY_28.add(day);
			case 28:
				DAY_29.add(day);
			case 29:
				DAY_30.add(day);
			case 30:
				DAY_31.add(day);
				break;
			}
		}

		for (int i = 0; i < 12; i++) {
			String month = (i + 1) + "";
			if (month.length() == 1) {
				month = "0" + month;
			}

			MONTH.add(month);
		}

		Calendar instance = Calendar.getInstance();
		int nowYear = instance.get(Calendar.YEAR);
		for (int i = 0; i < 200; i++) {
			YEAR_TOTAL.add((nowYear + i - 99) + "");
		}

	}

	public static ArrayList<String> getYearArrayTotal() {
		return YEAR_TOTAL;
	}

	public static ArrayList<String> getMonthArrayTotal() {
		return MONTH;
	}

	public static ArrayList<String> getDayArrayTotal(String yearStr, int monthPosition) {
		switch (monthPosition + 1) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			return DAY_31;
		case 2:
			int year = Integer.valueOf(yearStr);
			LogUtils.log("year:" + year);
			if (year % 4 == 0) {
				LogUtils.log("day_29");
				return DAY_29;
			} else {
				LogUtils.log("day_28");
				return DAY_28;
			}
		default:
			return DAY_30;
		}
	}

	public static String format(String before, String after, String dateStr) {
		try {
			Date date = null;
			try {
				date = new SimpleDateFormat(before).parse(dateStr);
			} catch (Exception e) {
				return "0000-00-00";
			}
			return format(after, date);
		} catch (Exception e) {
			// exception(e);
			return "0000-00-00";
		}
	}

	public static String format(String after, Date date) {
		try {
			return new SimpleDateFormat(after).format(date);
		} catch (Exception e) {
			// exception(e);
			return "0000-00-00";
		}
	}
}
